package com.jydd.liaomingframe.welcome;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.jydd.liaomingframe.R;
import com.jydd.ndktest.Encryptor;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * created by 韦敏敏
 * on 2019/11/28
 */
public class TestJniActivity extends AppCompatActivity {
    @BindView(R.id.btnEncrypt)
    Button btnEncrypt1;
    @BindView(R.id.btnDecrypt)
    Button btnDecrypt1;
    private String encryptPath;
    Encryptor encryptor = null;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_jni_test);
        ButterKnife.bind(this);
    }
    @OnClick({R.id.btnEncrypt, R.id.btnDecrypt})
    public void onClickEvent(View view){
        // 存储权限检验
        if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
                requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0X1024);
                return;
            }
        }
        switch (view.getId()){
            case R.id.btnEncrypt:

                encryptPath = encryptor.test();
                Toast.makeText(this, "加密文件地址：" + encryptPath, Toast.LENGTH_SHORT).show();
                break;
            case R.id.btnDecrypt:
               String decryptPath = new Encryptor().decryption(encryptPath);
                Toast.makeText(this, "解密文件地址：" + decryptPath, Toast.LENGTH_SHORT).show();
                break;
                default:
                    break;

        }


    }
}
